package cn.edu.demo.controller;

import cn.edu.demo.pojo.Passenger;
import cn.edu.demo.pojo.ResponseResult;
import cn.edu.demo.pojo.result.LoginResult;
import cn.edu.demo.pojo.result.OrderlistResult;
import cn.edu.demo.service.PassengerService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
//@Controller
public class PassengerController {

    @Autowired
    PassengerService service;

    @RequestMapping("/user/login")
    @ResponseBody
    public ResponseResult login(Long phone, String password){
//        System.out.println("phone: "+phone+" password: "+password);
        if(phone!=null&&password!=null){
            Passenger passenger = service.login(phone, password);
//        ObjectMapper objectMapper = new ObjectMapper();
            if(passenger!=null){
                return new ResponseResult(100, "登录成功", new LoginResult(passenger));
            }else{
                return new ResponseResult(101,"登录失败",null);
            }
        }else
            return new ResponseResult(103,"请输入账号或者密码",null);
    }
}
